<%@ page import = "org.apache.ibatis.io.Resources" %>
<%@ page import = "org.apache.ibatis.session.SqlSessionFactoryBuilder" %>
<%@ page import = "org.apache.ibatis.session.SqlSessionFactory" %>
<%@ page import = "java.io.InputStream" %>
<%@ page import = "org.apache.ibatis.session.SqlSession" %>
<%@ page import = "com.xiaozheng.dao.UserDao" %>
<%@ page import = "com.xiaozheng.domain.User" %>
<%@ page import = "java.util.List" %><%--
  Created by IntelliJ IDEA.
  User: Boy's love
  Date: 2020/9/16
  Time: 19:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType = "text/html;charset=UTF-8" language = "java" %>
<html>
    <head>
        <title>Title</title>
    </head>
    <body>
        <h1>helor word!!</h1>
        <%
            //1.读取配置文件 Resources是mybatis的工具类加载mybatis的配置文件
            InputStream in = Resources.getResourceAsStream("SqlMapConfig.xml");
            //2.创建SqlSessionFactory工厂
            SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
            //SqlSessionFactory不能new是个接口
            SqlSessionFactory factory = builder.build(in);///builder.build(in)构造工厂
            //3.使用工厂生产SqlSession对象
            SqlSession sqlSession = factory.openSession();
            //4.动态代理,使用SqlSession创建Dao的代理对象
            UserDao mapper = sqlSession.getMapper(UserDao.class);
            //5.使用代理对象执行方法
            List<User> users = mapper.findAll();
            for (User user : users) {
            System.out.println(user);
            }
            //6.释放资源
            sqlSession.close();
            in.close();
        %>
    </body>
</html>
